Skip to content

[SDK/Factories] Add argsSchema To The Factory Authoring Surface - #2315

Merged
MRayermannMSFT merged 2 commits into
mainfrom
mrayermannmsft-factory-args-schema
Aug 13, 2026
Merged

[SDK/Factories] Add argsSchema To The Factory Authoring Surface#2315
MRayermannMSFT merged 2 commits into
mainfrom
mrayermannmsft-factory-args-schema

Conversation

@MRayermannMSFT

@MRayermannMSFT MRayermannMSFT commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What

FactoryMeta now declares an optional argsSchema, so an extension author can state the argument shape their factory expects.

It reuses the existing FactoryJsonSchema type. That type already documents the same bounded subset the CLI enforces, and the runtime's own validator points at it as the contract boundary.

The field already crossed the wire, because defineFactory snapshots meta whole rather than cherry-picking fields. This change is additive and type-level. It makes an existing runtime feature discoverable to authors writing against the published types.

Docs and JSDoc now describe what a declaration enforces, matching the run_factory tool description word for word.

Why

Almost no factory declares an argument shape, because the SDK never exposed the field. Authors reading the published types cannot tell the feature exists.

That has a real cost. Without a declared schema nothing validates a caller's args. A malformed call starts a run, takes a user approval, spends credits, and then dies inside the factory body with a confusing error about a missing property.

With a declared schema the CLI catches the mismatch before the run starts. The model gets a correction hint and retries. No run row, no permission prompt, no credit spend.

Notes

  • nodejs/src/types.ts is hand-written, not generated. It already imports JsonValue from factory.ts, so importing FactoryJsonSchema alongside it follows the established convention.
  • No SDK-side shape validation was added. The runtime already rejects an out-of-subset declaration at registration, and duplicating that logic here would risk divergence.
  • argsSchema is optional. A factory that omits it behaves exactly as before, which a unit test asserts.
  • Enforcement is run_factory-path only. The runtime calls toolRunFactoryValidateArgs from runFactoryTool and nowhere else, so session.factory.run(...) is not validated. The docs and JSDoc say so explicitly, and a doc test pins that caveat, because an author would otherwise reasonably assume their own SDK-initiated runs were checked.

Testing

  • New unit test proves a declared argsSchema survives defineFactory, is deep-frozen, serializes to JSON, and reaches the session.resume registration payload. It also asserts an omitting factory carries no such property.
  • New doc test pins the SDK wording to the enforced subset and to the tool-path-only caveat, so the SDK and the run_factory tool cannot drift apart.
  • The argument-echo E2E fixture declares a schema, proving a declaration registers against a live runtime. It does not prove enforcement, since the E2E drives the SDK path.
  • nodejs unit suite, typecheck, lint, and format:check all pass. Three factory.e2e failures are pre-existing and reproduce identically on a clean tree.

FactoryMeta now declares an optional argsSchema, typed as the existing
FactoryJsonSchema. The field already crossed the wire because defineFactory
snapshots meta whole, so this is additive and type-level: it makes a runtime
feature discoverable to extension authors writing against the published types.

Without a declared schema nothing validates a caller's args. A malformed call
starts a run, takes a user approval, spends credits, and then fails inside the
factory body. With one, the CLI rejects it before the run row exists and the
model retries against a correction hint.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@MRayermannMSFT
MRayermannMSFT marked this pull request as ready for review August 12, 2026 04:18
@MRayermannMSFT
MRayermannMSFT requested a review from a team as a code owner August 12, 2026 04:18
Copilot AI balanced review requested due to automatic review settings August 12, 2026 04:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes factory argument schemas in the Node.js SDK and documents their runtime validation behavior.

Changes:

  • Adds optional FactoryMeta.argsSchema.
  • Documents supported schema constraints.
  • Adds unit and E2E coverage for schema transport.
Show a summary per file
File Description
nodejs/src/types.ts Adds the public metadata field.
nodejs/src/factory.ts Expands schema documentation.
nodejs/docs/factories.md Documents argument schemas and usage.
nodejs/test/factory.test.ts Tests freezing, serialization, and documentation.
nodejs/test/e2e/fixtures/factory-extension.mjs Adds a schema to the E2E fixture.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread nodejs/test/e2e/fixtures/factory-extension.mjs Outdated
Enforcement lives behind toolRunFactoryValidateArgs, which the runtime calls
only from runFactoryTool. session.factory.run does not validate, so the docs
and JSDoc now say which caller is checked instead of implying all of them are.

The argument-echo fixture declared ["object","null"] while its contract is to
echo any JsonValue, and it is invoked with an array. Nothing broke, because the
SDK path does not validate, but the narrow declaration was dishonest and would
have become load-bearing if that path ever gained validation. Widened it to the
factory's real contract and corrected the comment, which claimed the fixture
exercised enforcement when it only exercises registration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

This PR adds argsSchema to FactoryMeta in the Node.js/TypeScript SDK (nodejs/src/types.ts, nodejs/src/factory.ts).

Finding: No cross-SDK consistency issues.

The Agent Factories feature (defineFactory, joinSession, FactoryMeta) is a Node.js-exclusive SDK surface — it does not exist in the Python, Go, .NET, Java, or Rust SDKs. This PR extends a Node.js-only API with an optional field, so there is nothing to mirror in other languages.

The changes are internally consistent:

  • FactoryMeta.argsSchema reuses the existing FactoryJsonSchema type
  • The field is optional and backward compatible
  • Docs, JSDoc, and tests all describe the same enforcement boundary (run_factory path only)
  • The E2E fixture registers a declaration against the live runtime

No action required in other SDKs.

Generated by SDK Consistency Review Agent for #2315 · sonnet46 23.1 AIC · ⌖ 5.37 AIC · ⊞ 6.6K ·

@MRayermannMSFT
MRayermannMSFT added this pull request to the merge queue Aug 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 13, 2026
@MRayermannMSFT
MRayermannMSFT added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit 3b0d556 Aug 13, 2026
39 checks passed
@MRayermannMSFT
MRayermannMSFT deleted the mrayermannmsft-factory-args-schema branch August 13, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants